import { http } from "@/utils/http";

export type Payer = {
  id: number;
  payerType: number; // 1业主 2租户 3客户
  name: string;
  phone: string;
  email: string;
};

export type PayerSearchParams = {
  page: number;
  limit: number;
  name: string; // 模糊关键字，支持姓名/手机号
};

export type PayerSearchResult = {
  code: number;
  data: Payer[];
  message: string;
};

export type PayerBillQueryParams = {
  payerId: number;
  payerType: number;
};

// 账单项与未缴账单模块保持一致，并兼容历史账单新增字段 paymentype
export type PayerBillItem = import("@/api/unpaidBill").UnpaidBillItem & {
  paymentype?: number; // 1 预存款缴费 2 其他缴费
};

export type PayerBillQueryResult = {
  code: number;
  data: PayerBillItem[];
  message: string;
};

// 支付账单
export type BillPayBody = {
  ids: number[];
  payType: 1 | 2; // 1 预存款 2 其他
  amount: number; // 需支付的总金额
};

export type BillPayResult = {
  code: number;
  message: string;
};

// 缴费人模糊搜索
export const searchPayers = (params: PayerSearchParams) =>
  http.request<PayerSearchResult>("post", "/CheckStandController/Payerlist", {
    data: params
  });

// 查询未缴账单
export const queryPayerUnpaidBills = (params: PayerBillQueryParams) =>
  http.request<PayerBillQueryResult>(
    "post",
    "/CheckStandController/PayerBillQuery",
    { data: params }
  );

// 查询历史已缴账单
export const queryPayerPaidBills = (params: PayerBillQueryParams) =>
  http.request<PayerBillQueryResult>(
    "post",
    "/CheckStandController/PayerBillQueryPaied",
    { data: params }
  );

// 支付（可批量）
export const billPay = (body: BillPayBody) =>
  http.request<BillPayResult>("post", "/CheckStandController/BillPay", {
    data: body
  });
